$(document).ready(function(){
   var familyId=$.getUrlVar('familyId');
      var searchInfo={
          familyId:familyId,
          keyword:""//关键词
      };
      var table=$("#familymemberTable");
      var t=table.dataTable({
        "ajax":function(data,callback,setting){
          var page = table.api().page.info();
          $.post("/index.php?m=Admin&c=FamilyMember&a=search",{pageIndex:page.page+1,pageSize:page.length,select:searchInfo.keyword,family_id:searchInfo.familyId},function(data,status){
            console.log(data);
              callback(data); 
          });
        },

        "pageLength":10,
          "ordering":false,
          "deferRender": true,
          "columns":[
          {"data":"customer.id"},
          {"data":"customer.id"},
          {"data":"customer.customer_no"},
          {"data":"customer.name"},
          {"data":"customer.sex"},
          {"data":"customer.tel"},
          {"data":"customer.id_no"},
          {"data":"prefix"},
          {"data":"appellation"},
          {"data":"customer.status"},
          {"data":"customer.id"},
          ],
          "columnDefs":[
          {
            "targets":0,
            "data":"customer.id",
            "render":function(data,type,full,meta){
              return '<input type="checkbox" value="'+data+'" name="family_id">';
            }
          },
           {
            "targets":4,
            "data":"customer.sex",
            "render":function(data,type,full,meta){
               switch(data){
                    case 'F':
                      return "男";
                      break;
                    case 'M':
                      return "女";
                      break;
               }
            }
          },
           {
            "targets":9,
            "data":"customer.status",
            "render":function(data,type,full,meta){
               switch(data){
                    case '1':
                      return '<span class="c-success">激活状态</span>';
                      break;
                    case '0':
                      return '<span class="c-red">冻结状态</span>';
                      break;
               }
            }
          },
          {
            "targets":10,
            "data":"customer.id",
            "render":function(data,type,full,meta){
              switch(full.prefix){
                  case '户主':
                    var poStr='<a href="javascript:;" uid="'+data+'" class="label label-permission radius">设为户主</a><a title="编辑" href="javascript:;" uid="'+data+'" class="ml-5 familyEdit" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a><a title="删除" href="javascript:;" uid="'+data+'" class="ml-5 familyDel uid-'+data+'" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>';
                    break;
                  case '成员':
                    var poStr='<a href="javascript:;" uid="'+data+'" class="label label-success radius prefixBtn">设为户主</a><a title="编辑" href="javascript:;" uid="'+data+'" class="ml-5 familyEdit" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a><a title="删除" href="javascript:;" uid="'+data+'" class="ml-5 familyDel uid-'+data+'" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>';
                    break;
              }
              return poStr;
            }

          },
          ],
        "fnCreatedRow":function(row,data,index){
          //row 表示当前tr，data表示当前行的元素对象，index表示当前tr索引
        },
      "bPaginate": true, //翻页功能
      // "processing": true,
      "searching":false,
      "serverSide": true,//服务器模式
        });
$(".searchButton").click(function(){
      searchInfo.keyword=$("#searchName").val();
      t.api().draw();
    });
    // 回车事件
    document.onkeydown = function(e){
                 var ev = document.all ? window.event : e;
                 if(ev.keyCode==13) {
                   e.preventDefault();
                    searchInfo.keyword=$("#searchName").val();
                    t.api().draw();
                 }
            }
});